package com.itc.dispatch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itc.common.core.domain.R;
import com.itc.common.core.validate.Add;
import com.itc.common.core.validate.Delete;
import com.itc.common.core.validate.Update;
import com.itc.dispatch.domain.SysAlarmType;
import com.itc.dispatch.domain.SysFlowType;
import com.itc.dispatch.domain.dto.SysAlarmTypePageDto;
import com.itc.dispatch.domain.dto.SysFlowTypeDto;
import com.itc.dispatch.domain.dto.SysFlowTypePageDto;
import com.itc.dispatch.domain.vo.SysFlowTypeVo;
import com.itc.dispatch.service.SysAlarmTypeService;
import com.itc.dispatch.service.SysFlowTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/sys/flow")
@Api(value = "sysFlowType", tags = "流程类型管理模块")
public class SysFlowTypeController {

    @Autowired
    private SysFlowTypeService sysFlowTypeService;

    /**
     * 获取全部流程类型数据
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取全部流程类型数据")
    public R<List<SysFlowTypeVo>> getList(@RequestBody SysFlowType sysFlowType){
       return sysFlowTypeService.getList(sysFlowType);
    }

    /**
     * 流程类型列表数据分页获取
     */
    @PostMapping("/getPage")
    @ApiOperation(value = "流程类型列表数据分页获取")
    public R<Page<SysFlowTypeVo>> getPage( @RequestBody SysFlowTypePageDto pageDto){
        Page page = new Page();
        page.setCurrent(pageDto.getCurrent());
        page.setSize(pageDto.getSize());
        page.setSearchCount(true);
        return sysFlowTypeService.getPage(page,pageDto);
    }

    /**
     * 流程类型更新
     */
    @PostMapping("/update")
    @ApiOperation(value = "流程类型更新")
    public R update(@RequestBody @Validated(Update.class) SysFlowType sysFlowType){
        return sysFlowTypeService.updateOne(sysFlowType);
    }

    /**
     * 流程类型删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "流程类型删除")
    public R delete( @Validated(Delete.class) @RequestBody SysFlowTypeDto sysFlowTypeDto){
        return sysFlowTypeService.delete(sysFlowTypeDto);
    }

    /**
     * 流程类型新增
     */
    @PostMapping("/add")
    @ApiOperation(value = "流程类型新增")
    public R add(@RequestBody @Validated(Add.class) SysFlowTypeDto dto){
        return sysFlowTypeService.add(dto);
    }

}
